package com.chen.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chen.entity.Question;
import com.chen.mapper.QuestionMapper;
import com.chen.service.IQuestionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author personcoder007
 * @since 2022-08-16
 */
@Service
public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> implements IQuestionService {

    @Autowired
    private QuestionMapper questionMapper;


    /**
     * 根据试卷类型进行分页
     * @param pageNum  当前页
     * @param pageSize 每一页数
     * @param type 类型
     * @return
     */
    public Page<Question> findPage(Integer pageNum, Integer pageSize, Integer type,Integer courseId) {
        HashMap<String, Object> map = new HashMap<>();
        Page<Question> page = new Page<>(pageNum, pageSize);

        if (!"".equals(type)) {
            map.put("type", type);
        }

        if (!"".equals(courseId)) {
            map.put("courseId", courseId);
        }
        Page<Question> questionPage = questionMapper.findPage(page, map);
        return questionPage;
    }

    public Page<Question> getQuestionPage(Integer pageNum, Integer pageSize, Map<String, Object> params){
        Page<Question> page = new Page<>(pageNum, pageSize);

        Page<Question> questionPage = questionMapper.selectMutiContions(page, params);
        return questionPage;
    }


    public void delBath(List<Integer> ids){
        questionMapper.delBath(ids);
    }

}
